// Jie. 20250524 实现this对象的代码提示
const thisCompleter = {
  // 定义触发字符
  triggerCharacters: ['.'],

  getCompletions: function (editor, session, pos, prefix, callback) {
    // 定义this对象的方法和属性
    const thisCompletions = [
      {
        caption: 'formData',
        value: 'formData',
        meta: 'property',
        docText: '表单数据对象',
        type: 'object',
        score: 100
      },
      {
        caption: '$store',
        value: '$store',
        meta: 'property',
        docText: 'Vuex状态管理对象',
        type: 'object',
        score: 100
      },
      {
        caption: 'getUserInfo',
        value: 'getUserInfo',
        meta: 'property',
        docText: '获取当前用户信息',
        type: 'object',
        score: 100
      },
      {
        caption: '$message.info',
        value: "$message.info('')",
        meta: 'method',
        docText: 'Element消息提示',
        type: 'object',
        score: 100
      },
      {
        caption: '$message.error',
        value: "$message.error('')",
        meta: 'method',
        docText: 'Element消息提示组件',
        type: 'object',
        score: 100
      },
      {
        caption: '$message.success',
        value: "$message.success('')",
        meta: 'method',
        docText: 'Element消息提示组件',
        type: 'object',
        score: 100
      },
      {
        caption: '$message.warning',
        value: "$message.warning('')",
        meta: 'method',
        docText: 'Element消息提示组件',
        type: 'object',
        score: 100
      },
      {
        caption: '$router',
        value: '$router',
        meta: 'property',
        docText: '路由对象',
        type: 'object',
        score: 100
      },
      {
        caption: '$dialog',
        value: '$dialog',
        meta: 'property',
        docText: '对话框对象',
        type: 'object',
        score: 100
      },
      {
        caption: 'showDialog',
        value: 'showDialog',
        meta: 'method',
        docText: '显示对话框方法',
        type: 'function',
        score: 100
      },
      {
        caption: 'showOnlineDialog',
        value: 'showOnlineDialog',
        meta: 'method',
        docText: '显示在线对话框方法',
        type: 'function',
        score: 100
      },
      {
        caption: 'getFormWidget',
        value: 'getFormWidget()',
        meta: 'method',
        docText: '获取表单组件实例',
        type: 'function',
        score: 100
      },
      {
        caption: 'showMessage',
        value: 'showMessage(type, message)',
        meta: 'method',
        docText: '显示消息提示',
        type: 'function',
        score: 100
      },
      {
        caption: 'close',
        value: 'close()',
        meta: 'method',
        docText: '关闭当前页面',
        type: 'function',
        score: 100
      },
      {
        caption: 'doUrl',
        value: 'doUrl',
        meta: 'property',
        docText: 'axios请求对象',
        type: 'object',
        score: 100
      },
      {
        caption: 'tableInstance',
        value: 'tableInstance',
        meta: 'property',
        docText: '表格实例对象',
        type: 'object',
        score: 100
      }
    ];

    callback(null, thisCompletions);
  }
};

// 自定义定义代码片段
const customSnippet = [
  {
    name: 'consl',
    tabTrigger: 'console.log',
    content: `console.log('\${1:message}');`
  },
  {
    name: 'conserr',
    tabTrigger: 'console.error',
    content: `console.error('\${1:message}');`
  },
  {
    name: 'select*',
    tabTrigger: 'select',
    content: `select * from \${1:table} where \${2:condition}`
  },
  {
    name: 'insert*',
    tabTrigger: 'insert',
    content: `insert into \${1:table} (\${2:column1}, \${3:column2}) values (\${4:value1}, \${5:value2})`
  },
  {
    name: 'update*',
    tabTrigger: 'update',
    content: `update \${1:table} set \${2:column1} = \${3:value1}, \${4:column2} = \${5:value2} where \${6:condition}`
  },
  {
    name: 'delete*',
    tabTrigger: 'delete',
    content: `delete from \${1:table} where \${2:condition}`
  },
  {
    name: 'useDbLink*',
    tabTrigger: 'useDbLink',
    content: `api.useDblink('\${1:数据源名称}', true);`
  },
  {
    name: 'newQueryBuilder*',
    tabTrigger: 'newQueryBuilder',
    content: `var queryBuilder = new ApiQueryBuilder()
  .sql("\${1:sql}")
  .addParams(\${2:params})
  .pageParam(new MyPageParam(\${3:pageNum}, \${4:pageSize}))
  .relations(\${5:relations})
  .dictRelations(\${6:relationDicts});
      `
  },
  {
    name: 'doUrlget*',
    tabTrigger: 'doUrl.get',
    content: `doUrl('\${1:url}', 'get', \${2:params})
  .then(res => {
     console.log(res);
  })
  .catch(err => {
     console.error(err);
   });
      `
  },
  {
    name: 'doUrlpost*',
    tabTrigger: 'doUrl.post',
    content: `doUrl('\${1:url}', 'post', \${2:params})
  .then(res => {
     console.log(res);
  })
  .catch(err => {
     console.error(err);
   });
      `
  }
];

export { thisCompleter, customSnippet };
